package com.yuyang.wifi.dialog;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.yuyang.wifi.R;

import androidx.annotation.Nullable;


/**
 * 确认对话框
 */

public class CancelAndConfirmDialog extends CommonDialog {

    private TextView mDialogTitle, mDialogContent;
    private TextView mDialogConfirm, mDialogCancel;

    private String mTitle, mContent, mConfirmText, mCancelText;

    public static CancelAndConfirmDialog newInstance(String title, String content, String cancelText, String confirmText) {
        CancelAndConfirmDialog dialog = new CancelAndConfirmDialog();
        Bundle data = new Bundle();
        data.putString("title", title);
        data.putString("content", content);
        data.putString("cancelText", cancelText);
        data.putString("confirmText", confirmText);
        dialog.setArguments(data);
        return dialog;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mTitle = getArguments().getString("title");
        mContent = getArguments().getString("content");
        mCancelText = getArguments().getString("cancelText");
        mConfirmText = getArguments().getString("confirmText");
    }

    @Override
    public int getLayoutId() {
        return R.layout.dialog_cancel_and_confirm_layout;
    }


    @Override
    public void viewCreated(View view, @Nullable Bundle savedInstanceState) {
        mDialogTitle = (TextView) view.findViewById(R.id.dialog_title);
        mDialogContent = (TextView) view.findViewById(R.id.dialog_content);
        mDialogConfirm = (TextView) view.findViewById(R.id.dialog_confirm);
        mDialogCancel = (TextView) view.findViewById(R.id.dialog_cancel);
        mDialogTitle.setText(mTitle);
        mDialogContent.setText(mContent);
        mDialogConfirm.setText(mConfirmText);
        mDialogCancel.setText(mCancelText);

        mDialogConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (mDialogListener != null) {
                    mDialogListener.onConfirm();
                }
            }
        });

        mDialogCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }
}
